function init() {
    if(localStorage.appVersion == '1.4.1') return;

    if(localStorage.not_first_time_user) {
	version_1_3_fix();	// fix <Science> Fast Dial in version 1.3
    } else {	    	
	new_user_init();	// new users or version 1.2 users
    }

    version_1_4_1_init();
}

function version_1_4_1_init() {
    //register appVersion to version 1.4.1
    setItem('appVersion', '1.4.1');
}

function version_1_3_fix() {
    var len = Number(getItem('num_of_qs'));

    for(var i = 0; i < len; i++) {
	var Q = getItem( keyGen('Q', i) ).split('\t');

	if(Q[0]=='Science')  setItem( keyGen('Q', i), "Science"+"\t"+"\"http://www.sciencemag.org/cgi/search?volume=\"+vol+\"&firstpage=\"+page" );
    }
    removeItem('not_first_time_user');
}

function new_user_init(){
    clearStrg();    // remove all localstorage items;

    var j_name = ["Science", "Nature"];
    var j_urls = ["www.sciencemag.org", "www.nature.com"];
    var j_q    = ["\"http://www.sciencemag.org/cgi/search?volume=\"+vol+\"&firstpage=\"+page", "\"http://www.nature.com/search/executeSearch?sp-advanced=true&include-collections=journals_nature,crawled_content&exclude-collections=journals_palgrave,lab_animal&sp-m=0&sp-q=&sp-p=all&sp-q-9[NATURE]=1&sp-q-9[NPHYS]=1&sp-q-2=&sp-p-2=all&sp-q-3=&sp-p-3=all&sp-q-4=\"+vol+\"&sp-q-5=&sp-q-6=\"+page+\"&sp-q-10=&sp-q-11=&sp-q-12=&sp-start-month=&sp-start-year=&sp-end-month=&sp-end-year=&sp-date-range=0&sp-q-8=&sp-s=date_descending&sp-c=25\""];
    // register number of portals;
    setItem("num_of_portals", j_name.length);
    setItem("num_of_qs", j_q.length);
    for(var i = 0; i < j_name.length; i++) {
	var key_J = keyGen("J", i);
	var key_Q = keyGen("Q", i);
	setItem(key_J, j_name[i] +'\t'+ j_urls[i]);
	setItem(key_Q, j_name[i] +'\t'+ j_q[i]);
    }
}

function keyGen(type, k) {  
    return type + k;
}

